package example.service;

import net.sf.json.JSONArray;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class news_python {

    public static String new_python() throws Exception {
        String link = "http://www.cainong.cc/list/1.html";
        List<String> news=new ArrayList<>();
        List<String> herf=new ArrayList<>();

        Document document = Jsoup.connect(link).get();
        Elements links = document.select("a[href]");

        String str = "";
        String str1 = "";
        Map[] map = new Map[25];
        for (Element cycle : links) {
            str = cycle.text();
            str1 = cycle.attr("href");
            news.add(str);
            herf.add(str1);

        }

        for( int i = 84 ; i <= 132 ; i=i+2) {
            map[i/2-42]=new HashMap();
            map[i/2-42].put("text", news.get(i));
            map[i/2-42].put("href", herf.get(i));
        }

        JSONArray json2 = JSONArray.fromObject(map);

        return String.valueOf(json2);
    }


//    public static void main(String[] args) throws Exception {
//        System.out.println(huoquxinxi());
//
//    }

}
